package com.dqp.cslggroup.UI;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.Util.StringUtil;
import com.dqp.cslggroup.bean.Grade;

import java.util.List;


public class GradeAdapter extends BaseAdapter {
    private List<Grade> grades;
    private LayoutInflater inflater;
    private GradeAdapter gradeAdapter;

    public GradeAdapter(List<Grade> grades, Context context) {
        this.grades = grades;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return grades == null ? 0 : grades.size();
    }

    @Override
    public Object getItem(int position) {
        return grades.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = inflater.inflate(R.layout.grade_list, null);
        Grade grade = (Grade) getItem(position);
        TextView kc = view.findViewById(R.id.text_kc);
        TextView xf = view.findViewById(R.id.text_xf);
        TextView cj = view.findViewById(R.id.text_cj);
        TextView jd = view.findViewById(R.id.text_jd);
        int[] arr = StringUtil.SelectNumber(grade.getGrade());
        if (arr[0] < 60) {
            cj.setTextColor(Color.parseColor("#D81B60"));
            kc.setTextColor(Color.parseColor("#D81B60"));
            xf.setTextColor(Color.parseColor("#D81B60"));
            jd.setTextColor(Color.parseColor("#D81B60"));
        }

        kc.setText(grade.getCname());
        xf.setText(grade.getXf());
        cj.setText(grade.getGrade());
        jd.setText(grade.getJd());
        return view;

    }

}